﻿//********************************************************************************//
//创建日期：<创建日期，2016-04-19>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：用户复用信息
//********************************************************************************//
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Web.Class;
using DevExpress.Web;

namespace Web.Pages.YongShui
{
    public partial class YongHuFYXX : BasePage
    {
        #region 属性

        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int YONGHUFYXXID
        {
            get
            {
                return Convert.ToInt32(ViewState["YONGHUFYXXID"]);
            }
            set
            {
                ViewState["YONGHUFYXXID"] = value;
            }
        }

        /// <summary>
        /// 保存结果集
        /// </summary>
        private DataTable dtSource
        {
            get
            {
                return ViewState["dtSource"] as DataTable;
            }
            set
            {
                ViewState["dtSource"] = value;
            }
        }

        #endregion

        #region 变量

        /// <summary>
        /// 数据访问操作类
        /// </summary>
        SpHelper _spHelper = new SpHelper();

        /// <summary>
        /// 行政区对象
        /// </summary>
        YS_QT_YONGHUFYXX _YS_QT_YONGHUFYXX = new YS_QT_YONGHUFYXX();

        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 行政区BLL
        /// </summary>
        YS_QT_YONGHUFYXXBLL _YS_QT_YONGHUFYXXBLL = new YS_QT_YONGHUFYXXBLL();

        /// <summary>
        /// 操作日志BLL
        /// </summary>
        SYS_LOGBLL _SYS_LOGBLL = new SYS_LOGBLL();

        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitControl();
                InitData();
                LoadData(true);
                //Display();
            }
            else
            {
                LoadData(false);
            }
        }

        /// <summary>
        /// 绑定空表头
        /// </summary>
        protected override void Render(HtmlTextWriter sender)
        {
            base.Render(sender);
        }

        /// <summary>
        /// grid修改
        /// </summary>
        protected void lnbModify_Command(object sender, CommandEventArgs e)
        {

            ////其他逻辑判断
            //this.Status = GridViewStatus.Update;
            //Display();
            //SetData();
        }


        /// <summary>
        /// grid保存
        /// </summary>
        //protected void btnSave_Click(object sender, EventArgs e)
        //{
        //    if (ValidateData())
        //    {
        //        SaveData();
        //    }
        //}

        /// <summary>
        /// 查询
        /// </summary>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            LoadData(true);
        }

        /// <summary>
        /// 响应站点变化,加载对应管理块
        /// </summary>
        protected void concmbGuanLiK_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            LoadGuanLiK();
        }

        /// <summary>
        /// 响应站点变化,加载对应业务员
        /// </summary>
        protected void concmbYWY_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
        {
            LoadYWY();
        }

        /// <summary>
        /// 响应前台回调
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter.Contains("del"))
            {
                _YS_QT_YONGHUFYXX = _YS_QT_YONGHUFYXXBLL.SelectYS_QT_YONGHUFYXX(id);
                //无权限判断,判断当前登录是否为对应修改人 
                string xiugair = this.gvList1.GetRowValues(this.gvList1.FocusedRowIndex, "I_XIUGAIR").ToString();
                if (LoginInfo.CurrentUser.UserID.ToString() != xiugair && LoginInfo.CurrentUser.UserID != 72)
                {
                    cr.Msg = "你没有删除此用户的权限。";
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    e.Result = cr.ToString();
                    return;
                }
                //执行逻辑删除            
                _YS_QT_YONGHUFYXX.S_CAOZUOR = LoginInfo.CurrentUser.Account;
                _YS_QT_YONGHUFYXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _YS_QT_YONGHUFYXX.I_JLZT = -1;
                _SYS_LOGBLL.Log<YS_QT_YONGHUFYXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "用户复用信息", OperateState.Delete, _YS_QT_YONGHUFYXX, null);
                if (_YS_QT_YONGHUFYXXBLL.InsertOrUpdate(_YS_QT_YONGHUFYXX))
                {
                   
                    //LoadData(true);
                    cr.Msg = "操作成功！";
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = true;
                    e.Result = cr.ToString();
                }
            }
            else if (e.Parameter == "edit")
            {
                //无权限判断,判断当前登录是否为对应修改人 
                string xiugair = this.gvList1.GetRowValues(this.gvList1.FocusedRowIndex, "I_XIUGAIR").ToString();
                if (LoginInfo.CurrentUser.UserID.ToString() != xiugair && LoginInfo.CurrentUser.UserID != 72)
                {
                    cr.Msg = "你没有修改此用户的权限。";
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    e.Result = cr.ToString();
                    return;
                }
                //判断用户号
                string yonghuh = this.gvList1.GetRowValues(this.gvList1.FocusedRowIndex, "S_YONGHUH").ToString();
                DataRowCollection drc = this._YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic("S_YONGHUH=" + yonghuh, null).Rows;
                if (BusinessTool.ZHANDIANBH() != "00" && BusinessTool.ZHANDIANBH() != "51" && drc[0]["S_ZHANDIANBH"].ToString() != BusinessTool.ZHANDIANBH())
                {
                    cr.Msg = "您所在的部门不存在当前的用户号。";
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    e.Result = cr.ToString();
                    return;
                }
                if (drc[0]["I_KAOHEFY"].ToString() == "0")
                {
                    cr.Msg = "当前用户标记不考核复用，请修改。";
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    e.Result = cr.ToString();
                    return;
                }
                //用水数据判断 
                //YS_ZW_YINGYEZBLL bllTemp = new YS_ZW_YINGYEZBLL();
                //drc = bllTemp.SelectYS_ZW_YINGYEZsDynamic("S_YONGHUH='" + yonghuh + "' and I_Y=" + Convert.ToInt32(this.concmbY.Value) + " and I_M=" + Convert.ToInt32(this.concmbM.Value), null).Rows;
                //if (drc.Count == 0)
                //{
                //    cr.Msg = "当前用户在指定的水量年月没有计划数据，请修改。";
                //    cr.IsSuccess = false;
                //    cr.IsAlertMsg = true;
                //    e.Result = cr.ToString();
                //    return;
                //}
                _YS_QT_YONGHUFYXX = _YS_QT_YONGHUFYXXBLL.SelectYS_QT_YONGHUFYXX(id);
                cr.IsSuccess = true;
                cr.IsAlertMsg = false;
                cr.AddValue(this._YS_QT_YONGHUFYXX.S_CHANPIN1);
                cr.AddValue(this._YS_QT_YONGHUFYXX.S_CHANPIN2);
                cr.AddValue(this._YS_QT_YONGHUFYXX.S_CHANPIN3);
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_CHANPINYCL1);
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_CHANPINYCL2);
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_CHANPINYCL3);
                cr.AddValue(Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_CHONGFULYL).ToString("0.00"));
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_CHUANLIANYSFYL);
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_DANWEICPXSL1.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_DANWEICPXSL2.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_DANWEICPXSL3.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_DIBIAOSYSL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_DIXIASYSL.ToString());
                cr.AddValue(Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_GONGYIHYL).ToString("0.00"));
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_GONGYISFYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_GONGYISXSL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_GONGYISZYL);
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_GUOLUCQL);
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_GUOLUSXSL);
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_GUOLUSZYL);
                cr.AddValue(this.gvList1.GetRowValues(this.gvList1.FocusedRowIndex, "JUTV").ToString());
                cr.AddValue(Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_LENGLINGHYL).ToString("0.00"));
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_LENGLINGSFYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_LENGQUESFYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_LENGQUESXSL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_LENGQUESZYL.ToString());
                cr.AddValue(Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_LENGQUEXHL).ToString("0.00"));
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_QITAXSL.ToString());
                cr.AddValue(Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_SHENGHUOHYL).ToString("0.00"));
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_SHENGHUOYSFYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_SHENGHUOYSXSL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_SHENGHUOYSZYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_SHIJIYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_XINSHUILDH.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.S_YONGHUH);
                cr.AddValue(this.gvList1.GetRowValues(this.gvList1.FocusedRowIndex, "S_YONGHUM").ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_ZILAISYSL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.N_ZONGCHANZ.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_ZONGFUYL.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_ZONGXINSI.ToString());
                cr.AddValue(this._YS_QT_YONGHUFYXX.I_ZONGYONGSL.ToString());
                e.Result = cr.ToString();
                return;
            }
            else if (e.Parameter == "save")
            {
                OperateState operateState;
                //修改操作
                _YS_QT_YONGHUFYXX = _YS_QT_YONGHUFYXXBLL.SelectYS_QT_YONGHUFYXX(id);
                operateState = OperateState.Modify;
                this._YS_QT_YONGHUFYXX.S_CHANPIN1 = txtCHANPIN1.Text;
                this._YS_QT_YONGHUFYXX.S_CHANPIN2 = txtCHANPIN2.Text;
                this._YS_QT_YONGHUFYXX.S_CHANPIN3 = txtCHANPIN3.Text;
                this._YS_QT_YONGHUFYXX.N_CHANPINYCL1 = txtCHANPINYCL1.Text == "" ? null : (decimal?)decimal.Parse(txtCHANPINYCL1.Text);
                this._YS_QT_YONGHUFYXX.N_CHANPINYCL2 = txtCHANPINYCL2.Text == "" ? null : (decimal?)decimal.Parse(txtCHANPINYCL2.Text);
                this._YS_QT_YONGHUFYXX.N_CHANPINYCL3 = txtCHANPINYCL3.Text == "" ? null : (decimal?)decimal.Parse(txtCHANPINYCL3.Text);
                this._YS_QT_YONGHUFYXX.N_CHONGFULYL = txtCHONGFULYL.Text == "" ? null : (decimal?)decimal.Parse(txtCHONGFULYL.Text);
                this._YS_QT_YONGHUFYXX.I_CHUANLIANYSFYL = txtCHUANLIANYSFYL.Text == "" ? null : (decimal?)int.Parse(txtCHUANLIANYSFYL.Text);
                this._YS_QT_YONGHUFYXX.N_DANWEICPXSL1 = txtDANWEICPXSL1.Text == "" ? null : (decimal?)decimal.Parse(txtDANWEICPXSL1.Text);
                this._YS_QT_YONGHUFYXX.N_DANWEICPXSL2 = txtDANWEICPXSL2.Text == "" ? null : (decimal?)decimal.Parse(txtDANWEICPXSL2.Text);
                this._YS_QT_YONGHUFYXX.N_DANWEICPXSL3 = txtDANWEICPXSL3.Text == "" ? null : (decimal?)decimal.Parse(txtDANWEICPXSL3.Text);
                this._YS_QT_YONGHUFYXX.I_DIBIAOSYSL = txtDIBIAOSYSL.Text == "" ? null : (decimal?)int.Parse(txtDIBIAOSYSL.Text);
                this._YS_QT_YONGHUFYXX.I_DIXIASYSL = txtDIXIASYSL.Text == "" ? null : (decimal?)int.Parse(txtDIXIASYSL.Text);
                this._YS_QT_YONGHUFYXX.N_GONGYIHYL = txtGONGYIHYL.Text == "" ? null : (decimal?)decimal.Parse(txtGONGYIHYL.Text);
                this._YS_QT_YONGHUFYXX.I_GONGYISFYL = txtGONGYISFYL.Text == "" ? null : (decimal?)int.Parse(txtGONGYISFYL.Text);
                this._YS_QT_YONGHUFYXX.I_GONGYISXSL = txtGONGYISXSL.Text == "" ? null : (decimal?)int.Parse(txtGONGYISXSL.Text);
                this._YS_QT_YONGHUFYXX.I_GONGYISZYL = int.Parse(txtGONGYISZYL.Text);
                this._YS_QT_YONGHUFYXX.I_GUOLUCQL = txtGUOLUCQL.Text == "" ? null : (decimal?)int.Parse(txtGUOLUCQL.Text);
                this._YS_QT_YONGHUFYXX.I_GUOLUSXSL = txtGUOLUSXSL.Text == "" ? null : (decimal?)int.Parse(txtGUOLUSXSL.Text);
                this._YS_QT_YONGHUFYXX.I_GUOLUSZYL = int.Parse(txtGUOLUSZYL.Text);
                this._YS_QT_YONGHUFYXX.N_LENGLINGHYL = txtLENGLINGHYL.Text == "" ? null : (decimal?)decimal.Parse(txtLENGLINGHYL.Text);
                this._YS_QT_YONGHUFYXX.I_LENGLINGSFYL = txtLENGLINGSFYL.Text == "" ? null : (decimal?)int.Parse(txtLENGLINGSFYL.Text);
                this._YS_QT_YONGHUFYXX.I_LENGQUESFYL = txtLENGQUESFYL.Text == "" ? null : (decimal?)int.Parse(txtLENGQUESFYL.Text);
                this._YS_QT_YONGHUFYXX.I_LENGQUESXSL = txtLENGQUESXSL.Text == "" ? null : (decimal?)int.Parse(txtLENGQUESXSL.Text);
                this._YS_QT_YONGHUFYXX.I_LENGQUESZYL = int.Parse(txtLENGQUESZYL.Text);
                this._YS_QT_YONGHUFYXX.N_LENGQUEXHL = txtLENGQUEXHL.Text == "" ? null : (decimal?)decimal.Parse(txtLENGQUEXHL.Text);
                this._YS_QT_YONGHUFYXX.I_QITAXSL = txtQITAXSL.Text == "" ? null : (decimal?)int.Parse(txtQITAXSL.Text);
                this._YS_QT_YONGHUFYXX.N_SHENGHUOHYL = txtSHENGHUOHYL.Text == "" ? null : (decimal?)decimal.Parse(txtSHENGHUOHYL.Text);
                this._YS_QT_YONGHUFYXX.I_SHENGHUOYSFYL = txtSHENGHUOYSFYL.Text == "" ? null : (decimal?)int.Parse(txtSHENGHUOYSFYL.Text);
                this._YS_QT_YONGHUFYXX.I_SHENGHUOYSXSL = txtSHENGHUOYSXSL.Text == "" ? null : (decimal?)int.Parse(txtSHENGHUOYSXSL.Text);
                this._YS_QT_YONGHUFYXX.I_SHENGHUOYSZYL = int.Parse(txtSHENGHUOYSZYL.Text);
                this._YS_QT_YONGHUFYXX.I_SHIJIYL = txtSHIJIYL.Text == "" ? null : (decimal?)int.Parse(txtSHIJIYL.Text);
                this._YS_QT_YONGHUFYXX.N_XINSHUILDH = txtXINSHUILDH.Text == "" ? null : (decimal?)decimal.Parse(txtXINSHUILDH.Text);
                this._YS_QT_YONGHUFYXX.S_YONGHUH = this.txtYongHuH.Text;
                this._YS_QT_YONGHUFYXX.I_ZILAISYSL = txtZILAISYSL.Text == "" ? null : (decimal?)int.Parse(txtZILAISYSL.Text);
                this._YS_QT_YONGHUFYXX.N_ZONGCHANZ = txtZONGCHANZ.Text == "" ? null : (decimal?)decimal.Parse(txtZONGCHANZ.Text);
                this._YS_QT_YONGHUFYXX.I_ZONGFUYL = txtZONGFUYL.Text == "" ? null : (decimal?)int.Parse(txtZONGFUYL.Text);
                this._YS_QT_YONGHUFYXX.I_ZONGXINSI = int.Parse(txtZONGXINSI.Text);
                this._YS_QT_YONGHUFYXX.I_ZONGYONGSL = int.Parse(txtZONGYONGSL.Text);
                this._YS_QT_YONGHUFYXX.I_JLZT = 0;
                _YS_QT_YONGHUFYXX.S_CAOZUOR = this.UserID.ToString();
                this._YS_QT_YONGHUFYXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
                _SYS_LOGBLL.Log<YS_QT_YONGHUFYXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "用户复用信息", operateState, _YS_QT_YONGHUFYXX, null);
                if (_YS_QT_YONGHUFYXXBLL.InsertOrUpdate(_YS_QT_YONGHUFYXX))
                {
                    
                    cr.IsAlertMsg = true;
                    cr.IsSuccess = true;
                    cr.Msg = "保存成功！";
                    e.Result=cr.ToString();
                }
            }
        }



        #endregion

        #region 方法

        /// <summary>
        /// 初始化控件数据
        /// </summary>
        private void InitControl()
        {
            //获取当前水量年月
            int ym = BusinessTool.GetWaterYM();
            hdCollection.Set("ym", ym);
            //加载年
            for (int i = ym / 100; i > ym / 100 - 15; i--)
            {
                this.concmbY.Items.Add(i.ToString());
            }
            //加载月
            this.concmbM.Items.Add("全部", 0);
            for (int i = 1; i < ym % 100 + 1; i++)
            {
                this.concmbM.Items.Add(i.ToString(), i);
            }
            this.concmbY.SelectedIndex = 0;
            this.concmbY.Value = ym / 100;
            this.concmbM.Value = ym % 100;
            //根据操作人加载管理部门(站点)
            PageTools.LoadCombox(this.concmbZhanDian, PageTools.eLoadType.站点, BusinessTool.ZHANDIANBH(), "-", "");
            //加载站点下的管理块
            LoadGuanLiK();
            //加载业务员
            LoadYWY();
            //加载行政区
            PageTools.LoadCombox(this.concmbXingZhengQ, PageTools.eLoadType.行政区, BusinessTool.ZHANDIANBH(), null, "");
            //加载行业类型
            PageTools.LoadCombox(this.concmbHangYeLX, PageTools.eLoadType.行业类型, BusinessTool.ZHANDIANBH(), null, "");
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            gvList1.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
        }

        /// <summary>
        /// 数据加载
        /// </summary>
        private void LoadData(bool reGet)
        {
            if (reGet)
            {
                //string rsno = "-1";
                //string rsmsg = "";
                ////重新生成未输入的复用信息
                //this._spHelper.P_YS_RECREATEYHFYXX(Convert.ToInt32(this.concmbY.Value), Convert.ToInt32(this.concmbM.Value), out rsno, out rsmsg);
                //if (rsno == "-1")
                //{
                //    PageTools.AlertMsg(this, rsmsg);
                //    return;
                //}
                //计算条件
                string condition = "1=1";
                if (this.concmbYongShuiZBL.SelectedIndex != 0 && this.concmbYongShuiZBLPre.SelectedIndex != 0 && this.contxtYongShuiZBL.Text != "")
                {
                    condition = condition + " and " + this.concmbYongShuiZBL.Value.ToString() + this.concmbYongShuiZBLPre.Value.ToString() + this.contxtYongShuiZBL.Text;
                }
                if (this.concmbYongShuiZBLV.SelectedIndex != 0 && this.concmbYongShuiZBLVPre.SelectedIndex != 0 && this.contxtYongShuiZBLV.Text != "")
                {
                    condition = condition + " and " + this.concmbYongShuiZBLV.Value.ToString() + this.concmbYongShuiZBLVPre.Value.ToString() + this.contxtYongShuiZBLV.Text;
                }
                if (this.concmbXinShuiL.SelectedIndex != 0 && this.concmbXinShuiLPre.SelectedIndex != 0 && this.contxtXinShuiL.Text != "")
                {
                    condition = condition + " and " + this.concmbXinShuiL.Value.ToString() + this.concmbXinShuiLPre.Value.ToString() + this.contxtXinShuiL.Text;
                }
                this.dtSource = this._spHelper.P_YS_GETYONGHUFYXXVIEW(Convert.ToInt32(this.concmbY.Value), this.concmbM.SelectedIndex == 0 ? null : (int?)Convert.ToInt32(this.concmbM.Value)
                    , this.concmbZhanDian.SelectedIndex == 0 ? null : this.concmbZhanDian.Value.ToString()
                    , this.concmbGuanLiK.SelectedIndex == 0 ? null : this.concmbGuanLiK.Value.ToString()
                     , this.concmbXingZhengQ.SelectedIndex == 0 ? null : this.concmbXingZhengQ.Value.ToString()
                     , this.concmbYWY.SelectedIndex == 0 || this.concmbYWY.SelectedIndex == -1 ? null : (int?)Convert.ToInt32(this.concmbYWY.Value)
                     , this.contxtYongHuH.Text == "" ? null : this.contxtYongHuH.Text
                     , this.concmbYongShuiXZ.SelectedIndex == 0 ? null : this.concmbYongShuiXZ.Value.ToString()
                     , this.concmbHangYeLX.SelectedIndex == 0 ? null : this.concmbHangYeLX.Value.ToString()
                     , this.concmbShuRuLX.SelectedIndex == 0 ? null : (int?)Convert.ToInt32(this.concmbShuRuLX.Value)
                     , condition == "" ? null : condition).Tables[0];
                this.lblRecordCount.Text = "共有" + this.dtSource.Rows.Count.ToString() + "条记录";
            }
            gvList1.DataSource = this.dtSource;
            gvList1.DataBind();
            hdCollection.Set("rsY", this.concmbY.Text);
            hdCollection.Set("rsM", this.concmbM.Text);
        }

        /// <summary>
        ///用于控制添加、修改、查看三种状态的显示
        /// </summary>
        private void Display()
        {
            switch (this.Status)
            {
                case GridViewStatus.Init:
                    btnExportToExcel.Visible = true;
                    GridViewContentTable.Visible = false;
                    this.gvList1.Enabled = true;
                    break;
                case GridViewStatus.Search:
                    GridViewContentTable.Visible = true;
                    break;
                case GridViewStatus.Update:
                    btnExportToExcel.Visible = false;
                    GridViewContentTable.Visible = true;
                    this.gvList1.Enabled = false;
                    this.lblOperateTip.Text = "修改";
                    break;
                case GridViewStatus.Add:
                    btnExportToExcel.Visible = false;
                    GridViewContentTable.Visible = true;
                    this.gvList1.Enabled = false;
                    this.lblOperateTip.Text = "添加";
                    break;
            }
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        //private void SaveData()
        //{
        //    OperateState operateState;
        //    //修改操作
        //    _YS_QT_YONGHUFYXX = _YS_QT_YONGHUFYXXBLL.SelectYS_QT_YONGHUFYXX(this.YONGHUFYXXID, null);
        //    operateState = OperateState.Modify;
        //    this._YS_QT_YONGHUFYXX.S_CHANPIN1 = txtCHANPIN1.Text;
        //    this._YS_QT_YONGHUFYXX.S_CHANPIN2 = txtCHANPIN2.Text;
        //    this._YS_QT_YONGHUFYXX.S_CHANPIN3 = txtCHANPIN3.Text;
        //    this._YS_QT_YONGHUFYXX.N_CHANPINYCL1 = txtCHANPINYCL1.Text == "" ? null : (decimal?)decimal.Parse(txtCHANPINYCL1.Text);
        //    this._YS_QT_YONGHUFYXX.N_CHANPINYCL2 = txtCHANPINYCL2.Text == "" ? null : (decimal?)decimal.Parse(txtCHANPINYCL2.Text);
        //    this._YS_QT_YONGHUFYXX.N_CHANPINYCL3 = txtCHANPINYCL3.Text == "" ? null : (decimal?)decimal.Parse(txtCHANPINYCL3.Text);
        //    this._YS_QT_YONGHUFYXX.N_CHONGFULYL = txtCHONGFULYL.Text == "" ? null : (decimal?)decimal.Parse(txtCHONGFULYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_CHUANLIANYSFYL = txtCHUANLIANYSFYL.Text == "" ? null : (decimal?)int.Parse(txtCHUANLIANYSFYL.Text);
        //    this._YS_QT_YONGHUFYXX.N_DANWEICPXSL1 = txtDANWEICPXSL1.Text == "" ? null : (decimal?)decimal.Parse(txtDANWEICPXSL1.Text);
        //    this._YS_QT_YONGHUFYXX.N_DANWEICPXSL2 = txtDANWEICPXSL2.Text == "" ? null : (decimal?)decimal.Parse(txtDANWEICPXSL2.Text);
        //    this._YS_QT_YONGHUFYXX.N_DANWEICPXSL3 = txtDANWEICPXSL3.Text == "" ? null : (decimal?)decimal.Parse(txtDANWEICPXSL3.Text);
        //    this._YS_QT_YONGHUFYXX.I_DIBIAOSYSL = txtDIBIAOSYSL.Text == "" ? null : (decimal?)int.Parse(txtDIBIAOSYSL.Text);
        //    this._YS_QT_YONGHUFYXX.I_DIXIASYSL = txtDIXIASYSL.Text == "" ? null : (decimal?)int.Parse(txtDIXIASYSL.Text);
        //    this._YS_QT_YONGHUFYXX.N_GONGYIHYL = txtGONGYIHYL.Text == "" ? null : (decimal?)decimal.Parse(txtGONGYIHYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_GONGYISFYL = txtGONGYISFYL.Text == "" ? null : (decimal?)int.Parse(txtGONGYISFYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_GONGYISXSL = txtGONGYISXSL.Text == "" ? null : (decimal?)int.Parse(txtGONGYISXSL.Text);
        //    this._YS_QT_YONGHUFYXX.I_GONGYISZYL = int.Parse(txtGONGYISZYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_GUOLUCQL = txtGUOLUCQL.Text == "" ? null : (decimal?)int.Parse(txtGUOLUCQL.Text);
        //    this._YS_QT_YONGHUFYXX.I_GUOLUSXSL = txtGUOLUSXSL.Text == "" ? null : (decimal?)int.Parse(txtGUOLUSXSL.Text);
        //    this._YS_QT_YONGHUFYXX.I_GUOLUSZYL = int.Parse(txtGUOLUSZYL.Text);
        //    this._YS_QT_YONGHUFYXX.N_LENGLINGHYL = txtLENGLINGHYL.Text == "" ? null : (decimal?)decimal.Parse(txtLENGLINGHYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_LENGLINGSFYL = txtLENGLINGSFYL.Text == "" ? null : (decimal?)int.Parse(txtLENGLINGSFYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_LENGQUESFYL = txtLENGQUESFYL.Text == "" ? null : (decimal?)int.Parse(txtLENGQUESFYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_LENGQUESXSL = txtLENGQUESXSL.Text == "" ? null : (decimal?)int.Parse(txtLENGQUESXSL.Text);
        //    this._YS_QT_YONGHUFYXX.I_LENGQUESZYL = int.Parse(txtLENGQUESZYL.Text);
        //    this._YS_QT_YONGHUFYXX.N_LENGQUEXHL = txtLENGQUEXHL.Text == "" ? null : (decimal?)decimal.Parse(txtLENGQUEXHL.Text);
        //    this._YS_QT_YONGHUFYXX.I_QITAXSL = txtQITAXSL.Text == "" ? null : (decimal?)int.Parse(txtQITAXSL.Text);
        //    this._YS_QT_YONGHUFYXX.N_SHENGHUOHYL = txtSHENGHUOHYL.Text == "" ? null : (decimal?)decimal.Parse(txtSHENGHUOHYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_SHENGHUOYSFYL = txtSHENGHUOYSFYL.Text == "" ? null : (decimal?)int.Parse(txtSHENGHUOYSFYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_SHENGHUOYSXSL = txtSHENGHUOYSXSL.Text == "" ? null : (decimal?)int.Parse(txtSHENGHUOYSXSL.Text);
        //    this._YS_QT_YONGHUFYXX.I_SHENGHUOYSZYL = int.Parse(txtSHENGHUOYSZYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_SHIJIYL = txtSHIJIYL.Text == "" ? null : (decimal?)int.Parse(txtSHIJIYL.Text);
        //    this._YS_QT_YONGHUFYXX.N_XINSHUILDH = txtXINSHUILDH.Text == "" ? null : (decimal?)decimal.Parse(txtXINSHUILDH.Text);
        //    this._YS_QT_YONGHUFYXX.S_YONGHUH = this.txtYongHuH.Text;
        //    this._YS_QT_YONGHUFYXX.I_ZILAISYSL = txtZILAISYSL.Text == "" ? null : (decimal?)int.Parse(txtZILAISYSL.Text);
        //    this._YS_QT_YONGHUFYXX.N_ZONGCHANZ = txtZONGCHANZ.Text == "" ? null : (decimal?)decimal.Parse(txtZONGCHANZ.Text);
        //    this._YS_QT_YONGHUFYXX.I_ZONGFUYL = txtZONGFUYL.Text == "" ? null : (decimal?)int.Parse(txtZONGFUYL.Text);
        //    this._YS_QT_YONGHUFYXX.I_ZONGXINSI = int.Parse(txtZONGXINSI.Text);
        //    this._YS_QT_YONGHUFYXX.I_ZONGYONGSL = int.Parse(txtZONGYONGSL.Text);
        //    this._YS_QT_YONGHUFYXX.I_JLZT = 0;
        //    _YS_QT_YONGHUFYXX.S_CAOZUOR = this.UserID.ToString();
        //    this._YS_QT_YONGHUFYXX.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
        //    if (_YS_QT_YONGHUFYXXBLL.InsertOrUpdate(_YS_QT_YONGHUFYXX, null))
        //    {
        //        _SYS_LOGBLL.Log<YS_QT_YONGHUFYXX>(LoginInfo.CurrentUser, BusinessTool.WType.ToString(), "用户复用信息", operateState, _YS_QT_YONGHUFYXX, null);
        //        PageTools.AlertMsg(this, "保存成功！");
        //        this.Status = GridViewStatus.Init;
        //        Display();
        //        LoadData(true);
        //    }
        //    else
        //    {
        //        PageTools.AlertMsg(this, "保存失败！");
        //    }
        //}

        /// <summary>
        /// 给输入框赋值
        /// </summary>
        //private void SetData()
        //{
        //    _YS_QT_YONGHUFYXX = _YS_QT_YONGHUFYXXBLL.SelectYS_QT_YONGHUFYXX(this.YONGHUFYXXID, null);
        //    this.txtCHANPIN1.Text = this._YS_QT_YONGHUFYXX.S_CHANPIN1;
        //    this.txtCHANPIN2.Text = this._YS_QT_YONGHUFYXX.S_CHANPIN2;
        //    this.txtCHANPIN3.Text = this._YS_QT_YONGHUFYXX.S_CHANPIN3;
        //    this.txtCHANPINYCL1.Text = this._YS_QT_YONGHUFYXX.N_CHANPINYCL1.ToString();
        //    this.txtCHANPINYCL2.Text = this._YS_QT_YONGHUFYXX.N_CHANPINYCL2.ToString();
        //    this.txtCHANPINYCL3.Text = this._YS_QT_YONGHUFYXX.N_CHANPINYCL3.ToString();
        //    this.txtCHONGFULYL.Text = Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_CHONGFULYL).ToString("0.00");
        //    this.txtCHUANLIANYSFYL.Text = this._YS_QT_YONGHUFYXX.I_CHUANLIANYSFYL.ToString();
        //    this.txtDANWEICPXSL1.Text = this._YS_QT_YONGHUFYXX.N_DANWEICPXSL1.ToString();
        //    this.txtDANWEICPXSL2.Text = this._YS_QT_YONGHUFYXX.N_DANWEICPXSL2.ToString();
        //    this.txtDANWEICPXSL3.Text = this._YS_QT_YONGHUFYXX.N_DANWEICPXSL3.ToString();
        //    this.txtDIBIAOSYSL.Text = this._YS_QT_YONGHUFYXX.I_DIBIAOSYSL.ToString();
        //    this.txtDIXIASYSL.Text = this._YS_QT_YONGHUFYXX.I_DIXIASYSL.ToString();
        //    this.txtGONGYIHYL.Text = Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_GONGYIHYL).ToString("0.00");
        //    this.txtGONGYISFYL.Text = this._YS_QT_YONGHUFYXX.I_GONGYISFYL.ToString();
        //    this.txtGONGYISXSL.Text = this._YS_QT_YONGHUFYXX.I_GONGYISXSL.ToString();
        //    this.txtGONGYISZYL.Text = this._YS_QT_YONGHUFYXX.I_GONGYISZYL.ToString();
        //    this.txtGUOLUCQL.Text = this._YS_QT_YONGHUFYXX.I_GUOLUCQL.ToString();
        //    this.txtGUOLUSXSL.Text = this._YS_QT_YONGHUFYXX.I_GUOLUSXSL.ToString();
        //    this.txtGUOLUSZYL.Text = this._YS_QT_YONGHUFYXX.I_GUOLUSZYL.ToString();
        //    this.txtJu.Text = this.gvList1.GetRowValuesByKeyValue(this.YONGHUFYXXID, "JUTV").ToString();
        //    this.txtLENGLINGHYL.Text = Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_LENGLINGHYL).ToString("0.00");
        //    this.txtLENGLINGSFYL.Text = this._YS_QT_YONGHUFYXX.I_LENGLINGSFYL.ToString();
        //    this.txtLENGQUESFYL.Text = this._YS_QT_YONGHUFYXX.I_LENGQUESFYL.ToString();
        //    this.txtLENGQUESXSL.Text = this._YS_QT_YONGHUFYXX.I_LENGQUESXSL.ToString();
        //    this.txtLENGQUESZYL.Text = this._YS_QT_YONGHUFYXX.I_LENGQUESZYL.ToString();
        //    this.txtLENGQUEXHL.Text = Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_LENGQUEXHL).ToString("0.00");
        //    this.txtQITAXSL.Text = this._YS_QT_YONGHUFYXX.I_QITAXSL.ToString();
        //    this.txtSHENGHUOHYL.Text = Convert.ToDecimal(this._YS_QT_YONGHUFYXX.N_SHENGHUOHYL).ToString("0.00");
        //    this.txtSHENGHUOYSFYL.Text = this._YS_QT_YONGHUFYXX.I_SHENGHUOYSFYL.ToString();
        //    this.txtSHENGHUOYSXSL.Text = this._YS_QT_YONGHUFYXX.I_SHENGHUOYSXSL.ToString();
        //    this.txtSHENGHUOYSZYL.Text = this._YS_QT_YONGHUFYXX.I_SHENGHUOYSZYL.ToString();
        //    this.txtSHIJIYL.Text = this._YS_QT_YONGHUFYXX.I_SHIJIYL.ToString();
        //    this.txtXINSHUILDH.Text = this._YS_QT_YONGHUFYXX.N_XINSHUILDH.ToString();
        //    this.txtYongHuH.Text = this._YS_QT_YONGHUFYXX.S_YONGHUH;
        //    this.txtYongHuM.Text = this.gvList1.GetRowValuesByKeyValue(this.YONGHUFYXXID, "S_YONGHUM").ToString();
        //    this.txtZILAISYSL.Text = this._YS_QT_YONGHUFYXX.I_ZILAISYSL.ToString();
        //    this.txtZONGCHANZ.Text = this._YS_QT_YONGHUFYXX.N_ZONGCHANZ.ToString();
        //    this.txtZONGFUYL.Text = this._YS_QT_YONGHUFYXX.I_ZONGFUYL.ToString();
        //    this.txtZONGXINSI.Text = this._YS_QT_YONGHUFYXX.I_ZONGXINSI.ToString();
        //    this.txtZONGYONGSL.Text = this._YS_QT_YONGHUFYXX.I_ZONGYONGSL.ToString();
        //}

        /// <summary>
        /// 保存验证
        /// </summary>
        /// <returns></returns>
        //private bool ValidateData()
        //{
        //    //判断总新水量是否等于自来水新水量+地下水新水量+地表水新水量
        //    decimal valSum = 0;
        //    if (txtZILAISYSL.Text != "")
        //    {
        //        valSum = valSum + decimal.Parse(txtZILAISYSL.Text);
        //    }
        //    if (txtDIXIASYSL.Text != "")
        //    {
        //        valSum = valSum + decimal.Parse(txtDIXIASYSL.Text);
        //    }
        //    if (txtDIBIAOSYSL.Text != "")
        //    {
        //        valSum = valSum + decimal.Parse(txtDIBIAOSYSL.Text);
        //    }
        //    if (this.txtZONGXINSI.Text != valSum.ToString())
        //    {
        //        PageTools.AlertMsg(this, "新水量不等于各水量之和。");
        //        return false;
        //    }
        //    return true;
        //}

        /// <summary>
        /// 根据站点加载管理块
        /// </summary>
        private void LoadGuanLiK()
        {
            //加载站点下的管理块
            DataTable dtGLK = BusinessTool.GetTextAndValue(
                    "YS_JX_GUANLIK", "S_GUANLIKMC", "S_GUANLIKH", null, string.Format("s_zhandian='{0}'", this.concmbZhanDian.Value)
                ).Tables[0];
            DataRow drTemp = dtGLK.NewRow();
            drTemp[0] = "";
            drTemp[1] = "";
            dtGLK.Rows.InsertAt(drTemp, 0);
            PageTools.BindComboBox(
                this.concmbGuanLiK, dtGLK
            );
            if (this.concmbGuanLiK.Items.Count != 0)
            {
                this.concmbGuanLiK.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 根据站点加载业务员
        /// </summary>
        private void LoadYWY()
        {
            PageTools.LoadCombox(this.concmbYWY, PageTools.eLoadType.业务员, BusinessTool.ZHANDIANBH(), null, "");
        }

        #endregion

        protected void btnExport_Click(object sender, EventArgs e)
        {
            //string sName = "";
            //ASPxGridView gv = null;
            //DataTable dt = null;
            //gv = this.gvList1;
            //dt = this.dtSource;
            //sName = "用户复用信息";
            //gv.DataSource = dt;
            //gv.DataBind();
            //ASPxGridViewExporter1.GridViewID = gv.ID;
            //gv.Settings.ShowFooter = false;
            //ASPxGridViewExporter1.WriteXlsToResponse(sName);
            this.ASPxGridViewExporter1.GridViewID = "gvList1";
            this.gvList1.DataSource = this.dtSource;
            this.gvList1.DataBind();
            string sName = "用户复用信息";
            ASPxGridViewExporter1.WriteXlsToResponse(sName);
        }

    }
}